package homework;

import java.io.*;

public class Work02 {
    //把今天的作业中《我想对你说.txt》字符编码为GBK，
    // 复制到当前项目的testIO文件夹下的《章老师的话.txt》字符编码为UTF-8
    public static void main(String[] args) throws IOException {
        //D:\course\02-JavaSE进阶\day9-IO流\作业\我想对你说.txt
        //创建文件
        File file = new File("D:/course/02-JavaSE进阶/day9-IO流/作业/我想对你说.txt");
        File file1 = new File("day09-code/src/file/章老师的话.txt");
        //创建转换流
        InputStreamReader isr = null;
        //创建字节流
        OutputStreamWriter osw = null;
        try {
            FileInputStream fis = new FileInputStream(file);
            isr = new InputStreamReader(fis,"GBK");
            FileOutputStream fos  = new FileOutputStream(file1);
            osw = new OutputStreamWriter(fos,"UTF-8");

            char[] car = new char[1024];
            int len;
            while ((len = isr.read(car)) != -1){
                osw.write(car,0,len);
                osw.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        osw.close();
        isr.close();

    }
}
